import axios from 'axios'
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'
import store from '@/store'

const wyservice = axios.create({
    baseURL:'/wangyi',
    timeout:20000,
})

wyservice.interceptors.request.use((config)=>{
    let token = store.state.user.token
    if(token){
        config.headers.token = token
    }
    Nprogress.start()
    return  config
})

wyservice.interceptors.response.use((response)=>{
    Nprogress.done()
    return response.data
},(error)=>{
    Nprogress.done()
    alert('ajax请求失败')
    return new Promise(()=>{})
})

export default wyservice